package nc.ui.medpub.bd.hf00101009;

import java.util.Collection;

import nc.bs.framework.common.NCLocator;
import nc.bs.logging.Logger;
import nc.bs.uap.bd.BDRuntimeException;
import nc.itf.uap.IUAPQueryBS;
import nc.ui.pub.ClientEnvironment;
import nc.ui.trade.pub.IVOTreeDataByID;
import nc.vo.medpub.bd.hf00101009.PointMedOrgDefVO;
import nc.vo.pub.BusinessException;
import nc.vo.pub.SuperVO;

public class PointMedDefTreeCardData implements IVOTreeDataByID{

    private SuperVO[] m_PointMedDefVOs = null;

    public String getIDFieldName() {
        return PointMedOrgDefVO.PK_POINTMEDORGDEF;
    }

    public String getParentIDFieldName() {
        return PointMedOrgDefVO.VPARENT_ID;
    }

    public String getShowFieldName() {
        return PointMedOrgDefVO.VVERSION_NO +","+PointMedOrgDefVO.VVERSION_NAME;
    }

    public SuperVO[] getTreeVO() {
            IUAPQueryBS queryBS = (IUAPQueryBS) NCLocator.getInstance()
                    .lookup(IUAPQueryBS.class.getName());
            Collection<PointMedOrgDefVO> deptColl = null;
            try {
                StringBuffer strWhere = new StringBuffer(
                        "(pk_corp='0001' or pk_corp='").append(
                        ClientEnvironment.getInstance().getCorporation()
                                .getPrimaryKey()).append("')");
                strWhere.append(" and isnull(dr,0)=0 ");
                strWhere.append(" order by "+PointMedOrgDefVO.VVERSION_NO);
                deptColl = queryBS.retrieveByClause(PointMedOrgDefVO.class,
                        strWhere.toString());

            } catch (BusinessException e) {
                Logger.error(e.getMessage(), e);
                throw new BDRuntimeException(e.getMessage(), e);
            }
            if (deptColl == null){
                return null;
            }
            return m_PointMedDefVOs = (PointMedOrgDefVO[]) deptColl.toArray(new PointMedOrgDefVO[0]);
    }
}
